package teshop.data.domain;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@SuppressWarnings("serial")
@Entity
@Table(name = "CATEGORIES")
@NamedQueries({
	@NamedQuery(name = "Category.findByName", 
			query = "SELECT c FROM Category c WHERE c.name = :name"),
	@NamedQuery(name = "Category.findByDescription", 
			query = "SELECT c FROM Category c WHERE c.description = :description")
})
public class Category implements Serializable {

	@Id
	@Column(name = "CATEGORY_ID", nullable = false)
	private String id;

	@Column(name = "NAME", nullable = false)
	private String name;

	@Column(name = "DESCRIPTION", nullable = false)
	private String description;

	@Column(name = "IMAGEURL")
	private String imageurl;

	@OneToMany(cascade = CascadeType.ALL, mappedBy = "category")
	private Collection<Product> products;

	/** 
	 * Creates a new instance of Category 
	 */
	public Category() {
	}

	/**
	 * Creates a new instance of Category with the specified values.
	 * 
	 * @param categoryid
	 *            the categoryid of the Category
	 */
	public Category(String categoryid) {
		this.id = categoryid;
	}

	/**
	 * Creates a new instance of Category with the specified values.
	 * 
	 * @param categoryid
	 *            the categoryid of the Category
	 * @param name
	 *            the name of the Category
	 * @param description
	 *            the description of the Category
	 */
	public Category(String categoryid, String name, String description) {
		this.id = categoryid;
		this.name = name;
		this.description = description;
	}

	/**
	 * Gets the categoryid of this Category.
	 * 
	 * @return the categoryid
	 */
	public String getCategoryid() {
		return this.id;
	}

	/**
	 * Sets the categoryid of this Category to the specified value.
	 * 
	 * @param categoryid
	 *            the new categoryid
	 */
	public void setCategoryid(String categoryid) {
		this.id = categoryid;
	}

	/**
	 * Gets the name of this Category.
	 * 
	 * @return the name
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * Sets the name of this Category to the specified value.
	 * 
	 * @param name
	 *            the new name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Gets the description of this Category.
	 * 
	 * @return the description
	 */
	public String getDescription() {
		return this.description;
	}

	/**
	 * Sets the description of this Category to the specified value.
	 * 
	 * @param description
	 *            the new description
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * Gets the imageurl of this Category.
	 * 
	 * @return the imageurl
	 */
	public String getImageurl() {
		return this.imageurl;
	}

	/**
	 * Sets the imageurl of this Category to the specified value.
	 * 
	 * @param imageurl
	 *            the new imageurl
	 */
	public void setImageurl(String imageurl) {
		this.imageurl = imageurl;
	}

	/**
	 * Gets the productCollection of this Category.
	 * 
	 * @return the productCollection
	 */
	public Collection<Product> getProducts() {
		return this.products;
	}

	/**
	 * Sets the productCollection of this Category to the specified value.
	 * 
	 * @param productCollection
	 *            the new productCollection
	 */
	public void setProductCollection(Collection<Product> products) {
		this.products = products;
	}

	/**
	 * Returns a hash code value for the object. This implementation computes a
	 * hash code value based on the id fields in this object.
	 * 
	 * @return a hash code value for this object.
	 */
	@Override
	public int hashCode() {
		int hash = 0;
		hash += (this.id != null ? this.id.hashCode() : 0);
		return hash;
	}

	/**
	 * Determines whether another object is equal to this Category. The result
	 * is <code>true</code> if and only if the argument is not null and is a
	 * Category object that has the same id field values as this object.
	 * 
	 * @param object
	 *            the reference object with which to compare
	 * @return <code>true</code> if this object is the same as the argument;
	 *         <code>false</code> otherwise.
	 */
	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are
		// not set
		if (!(object instanceof Category)) {
			return false;
		}
		Category other = (Category) object;
		if (this.id != other.id
				&& (this.id == null || !this.id
						.equals(other.id)))
			return false;
		return true;
	}

	/**
	 * Returns a string representation of the object. This implementation
	 * constructs that representation based on the id fields.
	 * 
	 * @return a string representation of the object.
	 */
	@Override
	public String toString() {
		return "com.sun.javaee.blueprints.model.Category[categoryid="
				+ id + "]";
	}

}
